/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
 var largestSumAfterKNegations = function(nums, k) {
    for(let i = 0 ; i < k;){
        let num = nums[0]
        let minIndex = 0
        for(let j = 1 ; j < nums.length ; j++){
            nums[j] < num ? (num = nums[j],minIndex = j)  : null
        }
        nums[minIndex] = -nums[minIndex]
        k--
    }
    return eval(nums.join("+")) 
};
let num = largestSumAfterKNegations([3,-1,0,2],2)
console.log(num)